package com.youlai.utils;

import java.security.MessageDigest;

public class MD5Util {
    public static void main(String[] args) {
        String appId = "lyu9";
        String secret = "6d4b010a7554a66be55518d4b9a00b40";
        String timestamp = "1712475979492";
        String nonce = "5452144";
        StringBuilder sb = new StringBuilder();
        sb.append(appId).append("&");
        sb.append(secret).append("&");
        sb.append(timestamp).append("&");
        sb.append(nonce);
        String sign = MD5Util.md5Password(sb.toString());

        System.out.println("sign="+sign);
    }

    /**
     * md5加密方法
     * @param password
     * @return
     */
    public static String md5Password(String password) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(password.getBytes());
            byte[] b = md.digest();
            StringBuffer buf = new StringBuffer();

            for(int offset = 0; offset < b.length; ++offset) {
                int i = b[offset];
                if (i < 0) {
                    i += 256;
                }

                if (i < 16) {
                    buf.append("0");
                }

                buf.append(Integer.toHexString(i));
            }

            return buf.toString();
        } catch (Exception var6) {
            return "";
        }
    }
}
